package ${packageName};

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import ${basePackageName}entity.base.BoPage;
import ${basePackageName}entity.base.JsonResult;
import ${basePackageName}entity.${className};
import ${basePackageName}entity.bean.${className}Req;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.web.client.RestTemplate;

/**
 * @author： XW -> ~
 * @create： 2024/5/29 14:06
 */
@Slf4j
public class ${className}ControllerTest {

    // 数据库中的数据量
    private int dataSize = 10;

    private int createSize = 5;

    @Test
    public void simpleControlPageTest() {
        RestTemplate restTemplate = new RestTemplate();
        String url = "http://localhost:8414/vv/${className?uncap_first}/page/1/1";
        String pub = restTemplate.getForObject(url, String.class);
        JsonResult<BoPage<${className}>> jsonResult = JSON.parseObject(pub, new TypeReference<JsonResult<BoPage<${className}>>>() {
        });
        if (jsonResult == null) {
            log.error("返回空的");
        }
        if (jsonResult.getData() == null) {
            log.error("BoPage是空的");
        }
        if (jsonResult.getData().getTotal() == 0 && dataSize != 0) {
            log.error("返回结果显示数据库中没有数据！！！");
        }
        log.info("boPage.size = {}", jsonResult.getData().getTotal());
    }

    @Test
    public void reqControlPageTest() {
        RestTemplate restTemplate = new RestTemplate();
        String url = "http://localhost:8414/vv/${className?uncap_first}/pageReq";

        ${className}Req ${className?uncap_first}Req = new ${className}Req();
        ${className?uncap_first}Req.setPageNumber(1);
        ${className?uncap_first}Req.setPageSize(1);

        String pub = restTemplate.postForObject(url, JSON.toJSON(${className?uncap_first}Req), String.class);
        JsonResult<BoPage<${className}>> jsonResult = JSON.parseObject(pub, new TypeReference<JsonResult<BoPage<${className}>>>() {
        });
        if (jsonResult == null) {
            log.error("返回空的");
        }
        if (jsonResult.getData() == null) {
            log.error("BoPage是空的");
        }
        if (jsonResult.getData().getTotal() == 0 && dataSize != 0) {
            log.error("返回结果显示数据库中没有数据！！！");
        }
        log.info("boPage.size = {}", jsonResult.getData().getTotal());
    }


}
